/*
 * Equipamento.java
 *
 * Created on 19 de Setembro de 2007, 02:10
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 *
 *
 */

package brosim.bean;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 *
 * @author Hugo
 */
public class Equipment {
    private int id = 0;
    private String name;
    private String group;
    private double weight;
    private int slot;
    private int price;
    private int weaponLV;
    private int requiredLV;
    private int sex;
    private int upgradable;
    private int atk;
    private int def;
    private int perDef;
    private int element;
    private int atkM;
    private int defM;
    private int perDefM;
    private Collection bonus = new ArrayList();
    private Collection skills = new ArrayList();

    private int refine; 
    private Card card1;
    private Card card2;
    private Card card3;
    private Card card4;

    /** Creates a new instance of Equipamento */
    public Equipment() {
        
    }

	public Equipment(int id, String name, String group, double weight, int slot, int price, int weaponlv, int requiredlv, int sex, int upgradable, int atk, int def, int def2, int element, int atkm, int defm, int perDefM) {
		// TODO Auto-generated constructor stub
		this.id = id;
		this.name = name;
		this.group = group;
		this.weight = weight;
		this.slot = slot;
		this.price = price;
		this.weaponLV = weaponlv;
		this.requiredLV = requiredlv;
		this.sex = sex;
		this.upgradable = upgradable;
		this.atk = atk;
		this.def = def;
		this.perDef = def2;
		this.element = element;
		this.atkM = atkm;
		this.defM = defm;
		this.perDefM = perDefM;
	}



	public int getAtk() {
		return atk;
	}

	public int getAtkM() {
		return atkM;
	}

	public int getDef() {
		return def;
	}

	public int getDefM() {
		return defM;
	}

	public int getElement() {
		return element;
	}

	public String getGroup() {
		return group;
	}

	public int getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public int getPerDef() {
		return perDef;
	}

	public int getPerDefM() {
		return perDefM;
	}

	public int getPrice() {
		return price;
	}

	public int getRequiredLV() {
		return requiredLV;
	}

	public int getSex() {
		return sex;
	}

	public int getSlot() {
		return slot;
	}

	public int getUpgradable() {
		return upgradable;
	}

	public int getWeaponLV() {
		return weaponLV;
	}

	public double getWeight() {
		return weight;
	}

	public void setAtk(int atk) {
		this.atk = atk;
	}

	public void setAtkM(int atkM) {
		this.atkM = atkM;
	}

	public void setDef(int def) {
		this.def = def;
	}

	public void setDefM(int defM) {
		this.defM = defM;
	}

	public void setElement(int element) {
		this.element = element;
	}

	public void setGroup(String group) {
		this.group = group;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setPerDef(int perDef) {
		this.perDef = perDef;
	}

	public void setPerDefM(int perDefM) {
		this.perDefM = perDefM;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public void setRequiredLV(int requiredLV) {
		this.requiredLV = requiredLV;
	}

	public void setSex(int sex) {
		this.sex = sex;
	}

	public void setSlot(int slot) {
		this.slot = slot;
	}

	public void setUpgradable(int upgradable) {
		this.upgradable = upgradable;
	}

	public void setWeaponLV(int weaponLV) {
		this.weaponLV = weaponLV;
	}

	public void setWeight(double weight) {
		this.weight = weight;
	}

	public Collection getBonus() {
		return bonus;
	}

	public Collection getSkills() {
		return skills;
	}

	public void setBonus(Collection bonus) {
		this.bonus = bonus;
	}

	public void setSkills(Collection skills) {
		this.skills = skills;
	}

	public int getRefine() {
		return refine;
	}

	public void setRefine(int refine) {
		this.refine = refine;
	}

	public Card getCard1() {
		return card1;
	}

	public Card getCard2() {
		return card2;
	}

	public Card getCard3() {
		return card3;
	}

	public Card getCard4() {
		return card4;
	}

	public void setCard1(Card card1) {
		this.card1 = card1;
	}

	public void setCard2(Card card2) {
		this.card2 = card2;
	}

	public void setCard3(Card card3) {
		this.card3 = card3;
	}

	public void setCard4(Card card4) {
		this.card4 = card4;
	}
    
	public int getAllDef() {
		int value = def;
        value += card1.getDef();
        value += card2.getDef();
        value += card3.getDef();
        value += card4.getDef();		
		return value;
	}

	public int getAllPerDef() {
		int value = perDef;
        value += card1.getPerDef();
        value += card2.getPerDef();
        value += card3.getPerDef();
        value += card4.getPerDef();		
		return value;
	}

    public double getBonusEquip(int id) {
        double value = 0;
        Iterator i = bonus.iterator();
        while (i.hasNext()) {
            int[] b = (int[])i.next();
            if (b[0] == id) {
                value += b[1];
            }
        }
        return value;
    }

    public double getBonusCard(int id) {
        double value = 0;
        if (card1 != null && card1.getId() != 0)
            value += card1.getBonusValue(id);
        if (card2 != null && card2.getId() != 0)
            value += card2.getBonusValue(id);
        if (card3 != null && card3.getId() != 0)
            value += card3.getBonusValue(id);
        if (card4 != null && card4.getId() != 0)
            value += card4.getBonusValue(id);
        return value;
    }

    public double getBonusAll(int id) {
        return getBonusEquip(id) + getBonusCard(id);
    }
    
    public int searchCard(int id) {
        int count = 0;
        if (card1 != null && card1.getId() != 0)
            count += card1.getId() == id ? 1 : 0;
        if (card2 != null && card2.getId() != 0)
            count += card2.getId() == id ? 1 : 0;
        if (card3 != null && card3.getId() != 0)
            count += card3.getId() == id ? 1 : 0;
        if (card4 != null && card4.getId() != 0)
            count += card4.getId() == id ? 1 : 0;
        return count;
    }
    
}
